package com.polukeuro.app.controllers;

import java.util.List;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.polukeuro.app.model.action.Pronostic;
import com.polukeuro.app.model.entity.Group;
import com.polukeuro.app.tests.TestUtils;

@Controller
public class TestController {
	
	@RequestMapping(method=RequestMethod.GET,value="/test.json", headers="Accept=application/json")
	public @ResponseBody String getHelloWorld(){
		
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("hello", "world");
		return jsonObject.toString(4);
	}
	
	@RequestMapping(method=RequestMethod.GET,value="pronostic/{id}.json", headers="Accept=application/json")
	public @ResponseBody Pronostic getPronostic(@PathVariable String id){
		Pronostic p = new Pronostic();
		p.setId(Integer.parseInt(id));
		p.setName("mon premier pronostic");
		return p;
	}
	
	
	@RequestMapping("/getGroups.json")
	public @ResponseBody List<Group> getGroups(){
		return TestUtils.getGroups();
	}
	
	@RequestMapping(method=RequestMethod.GET,value="/getGroup/{id}.json", headers="Accept=application/json")
	public @ResponseBody Group getGroup(@PathVariable String id){
		return TestUtils.getGroup(id);
	}
	
}
